package com.hkbigdata.springbootdi.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.hkbigdata.springbootdi.bean.OrderStatus;
import com.hkbigdata.springbootdi.bean.ProvinceData;
import com.hkbigdata.springbootdi.bean.SaleAmount;
import com.hkbigdata.springbootdi.bean.SaleAmountTotal;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author liuanbo
 * @creat 2024-11-27-15:23
 * @see 2194550857@qq.com
 */
@Mapper
@DS("mysql")
public interface OrderStatusMapper {
    @Select("" +
            "select " +
            "    date_format(dt,'%H:%i') as `time`," +
            "    sum(orderCount) as orderCount," +
            "    sum(refundCount) as refundCount" +
            "    from di" +
            " where date(dt)='${dt}'" +
            " group by date_format(dt,'%H:%i')" +
            " order by `time`" +
            ";")
    List<OrderStatus> queryOrderStatusList(@Param("dt") String dt);

    @DS("ck")
    @Select("select brand as brand," +
            "        sum(saleAmount) as amount " +
            "       from di where toDate(dt)=today()" +
            " group by brand" +
            ";")
    List<SaleAmount> querySaleAmountList();


    @DS("ck")
    @Select("select a.brand              as brand," +
            "       a.todaySaleAmount    as todaySaleAmount," +
            "       b.yestodaySaleAmount as yestodaySaleAmount," +
            "       c.passweekSaleAmount as passweekSaleAmount" +
            " from (select brand, sum(saleAmount) as todaySaleAmount from di where toDate(dt) = today() group by brand) as a" +
            "         full join (select brand, sum(saleAmount) as yestodaySaleAmount" +
            "                    from di" +
            "                    where toDate(dt) = today() - 1" +
            "                    group by brand) as b" +
            "                   on a.brand = b.brand" +
            "         full join (select brand, sum(saleAmount) as passweekSaleAmount" +
            "                    from di" +
            "                    where toDate(dt) = today() - 7" +
            "                    group by brand) as c" +
            "                   on a.brand = c.brand;")
    List<SaleAmountTotal> querySaleAmountTotalList();

    @DS("ck")
    @Select("select" +
            "    sum(saleamount) as amount" +
            "     from ditohbase" +
            "  where toDate(dt)=today() and province=#{province};")
    Double querySaleAmount(@Param("province") String province);
    
    @DS("ck")
    @Select("select" +
            "    province as name," +
            "    sum(orderCount) as value," +
            "    sum(saleamount) as sizeValue" +
            " from ditohbase" +
            " where toDate(dt)=today()" +
            " group by province" +
            ";")
    List<ProvinceData> queryProvinceData();
}
